package se.hh.service;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.UserLoginDao;
import se.hh.lab.dao.impl.UserLoginDaoImpl;
import se.hh.lab.domain.Login;

public class UserLogin extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{ 
		
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		HttpSession session=request.getSession();
		
		Login login=new Login();
		login.setPassword(password);
		login.setUserID(username);
		
		UserLoginDao userlogin=new UserLoginDaoImpl();
		int flag =userlogin.getUserLogin(login);

		if(flag == 1)
		{		
			session.setAttribute("userlogin", login);
			request.getRequestDispatcher("user_main.jsp").forward(request, response);
			
		}
		else
		{
			response.sendRedirect("user_login.jsp");
			return;
		}
			
			
		
		
	}

}
